package com.zhouxianglh.week156;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class First {
    public static void main(String[] args) {
        System.out.println(uniqueOccurrences(new int[]{1, 2, 2, 1, 1, 3}));
        System.out.println(uniqueOccurrences(new int[]{1, 2}));
        System.out.println(uniqueOccurrences(new int[]{-3, 0, 1, -3, 1, 1, 1, -3, 10, 0}));
    }

    public static boolean uniqueOccurrences(int[] arr) {
        if (null == arr || arr.length == 0) {
            return true;
        }
        Map<Integer, Integer> countMap = new HashMap<>();
        for (int i : arr) {
            if (null == countMap.get(i)) {
                countMap.put(i, 1);
            } else {
                countMap.put(i, countMap.get(i) + 1);
            }
        }
        Set<Integer> setCount = new HashSet<>();
        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            if (!setCount.add(entry.getValue())) {
                return false;
            }
        }
        return true;
    }
}
